package com.taptech.doufu.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.taptech.doufu.R;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.constant.Constant;

/**
 * Created by Administrator on 2017/4/20/020.
 */
public class GlideUtil {

    /**
     * 显示普通图片
     * @param context
     * @param into
     * @param url
     */
    public static void displayImage(Context context, ImageView into, String url) {
        url = Constant.changeUrlHost(url);
        Glide.with(context).load(url).centerCrop().dontAnimate().into(into);
    }


    /**
     *
     * @param into
     * @param url
     * @param width   dp
     * @param height  dp
     */
    public static void displayImage(ImageView into,String url,int width,int height){
        url = Constant.changeUrlHost(url);
        Glide.with(WeMediaApplication.applicationContext)
                .load(url)
                .override(ScreenUtil.dip2px(WeMediaApplication.applicationContext,width),
                        ScreenUtil.dip2px(WeMediaApplication.applicationContext,height))
                .into(into);
    }


    public static void displayImage(ImageView into, String url) {
        url = Constant.changeUrlHost(url);
        displayImage(WeMediaApplication.applicationContext,into,url);
    }

    public static void displayImage(ImageView imageView,String url,int placeholder) {
        url = Constant.changeUrlHost(url);
        Glide.with(WeMediaApplication.applicationContext)
                .load(url)
                .dontAnimate()
                .placeholder(placeholder)
                .transform(new CenterCrop(),new GlideRoundTransform(WeMediaApplication.applicationContext))
                .into(imageView);
    }

    /**
     * 显示圆形图片
     * @param context
     * @param into
     * @param url
     */
    public static void displayCircleImage(Context context, ImageView into, String url){
        url = Constant.changeUrlHost(url);
        Glide.with(context)
                .load(url)
                .centerCrop()
                .dontAnimate()
                .transform(new GlideCircleTransform(context))
                .into(into);
    }

    public static void displayCircleImage(Context context, ImageView into, int resource){
        Glide.with(context)
                .load(resource)
                .centerCrop()
                .dontAnimate()
                .transform(new GlideCircleTransform(context))
                .into(into);
    }

    /**
     * 显示圆角图片
     *
     * @param into
     * @param url
     */
    public static void displayRoundImage(Context context, ImageView into, String url,int radius) {
        url = Constant.changeUrlHost(url);
        Glide.with(context)
                .load(url)
                .transform(new CenterCrop(),new GlideRoundTransform(context,radius))
                .dontAnimate()
                .into(into);
    }


    public static void displayRoundImage(Context context, ImageView into, String url,int radius,int placeholder) {
        url = Constant.changeUrlHost(url);
        Glide.with(context)
                .load(url)
                .placeholder(placeholder)
                .transform(new CenterCrop(),new GlideRoundTransform(context,radius))
                .dontAnimate()
                .into(into);
    }

    public static void displayRoundImage(ImageView into, String url,int radius,int placeholder) {
        displayRoundImage(WeMediaApplication.applicationContext,into,url,radius,placeholder);
    }

    public static void displayRoundImage(ImageView into, String url,int radius) {
        displayRoundImage(WeMediaApplication.applicationContext,into,url,radius);
    }

    public static void displayRoundImage(Context context, ImageView into, byte[] data,int radius) {

        Glide.with(context)
            .load(data)
            .transform(new CenterCrop(),new GlideRoundTransform(context,radius))
            .dontAnimate()
            .into(into);
    }

    public static void displayRoundImage(ImageView into, byte[] data,int radius) {
        displayRoundImage(WeMediaApplication.applicationContext,into,data,radius);
    }


        public static void displayCircleImage(ImageView into, String url) {
        displayCircleImage(WeMediaApplication.applicationContext,into,url);
    }

    public static void displayCircleImageBorder(ImageView into, String url) {
        displayCircleImageBorder(into, url, 1, WeMediaApplication.applicationContext.getResources().getColor(R.color.border_color_1));
    }

    public static void displayCircleImageBorder(ImageView into, String url, int borderWidth, int borderColor) {
        displayCircleImageBorder(WeMediaApplication.applicationContext,into,url,borderWidth,borderColor);
    }

    public static void displayCircleImageBorder(Context context,ImageView into, String url, int borderWidth, int borderColor) {
        url = Constant.changeUrlHost(url);
        Glide.with(context)
                .load(url)
                .centerCrop()
                .dontAnimate()
                .transform(new GlideCircleTransform(context,borderWidth,borderColor))
                .into(into);
    }
}
